﻿#define USE_SLIMDX
//#define USE_XNA

#region Dependencies

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;

using XNA = Microsoft.Xna.Framework;
using SDX = SlimDX;
using SysDrawing = System.Drawing;
using PhysX = StillDesign.PhysX;
using BEPU = BEPUphysics;

#if USE_SLIMDX
using SlimDX;
using SlimDX.Direct3D10;
using SlimDX.DirectInput;
using SlimDX.DirectSound;
using SlimDX.DirectWrite;
using SlimDX.DXGI;
using SlimDX.Multimedia;
using SlimDX.Windows;
using SlimDX.X3DAudio;
using SlimDX.XACT3;
using SlimDX.XAPO;
using SlimDX.XAudio2;
#endif

#if USE_XNA
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Design;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

using Xen2D;
using XenAspects;
using XenGameBase;
#endif

#endregion // Dependencies

using Blackrain;

namespace Blackrain.Core.Windows
{
    public class GameWindow
    {
        private int instanceId;
        private string windowTitle;
        private Vector2 windowSize = Vector2.Zero;
        private Vector2 windowPosition = Vector2.Zero;
        private bool windowResizable = false;
        private bool windowMouseEnabled = false;
        private bool windowFullscreen = false;
        private IntPtr windowHandle = IntPtr.Zero;

        public IntPtr Handle
        {
            get { return windowHandle; }
        }

        private RenderForm renderForm = null;

        public GameWindow()
        {
            instanceId = 0;
            windowTitle = "BLACKRAIN";
            windowSize = new Vector2( 750, 550 );
            windowPosition = Vector2.Zero;

            windowResizable = false;
            windowMouseEnabled = false;
            windowFullscreen = false;

            renderForm = new RenderForm( this.windowTitle );

            windowHandle = renderForm.Handle;

            Run( );
        }

        public GameWindow( string title )
            : this( )
        {
            renderForm = new RenderForm( title );

            renderForm.Paint += new PaintEventHandler( renderForm_Paint );
        }

        private void renderForm_Paint( object sender, PaintEventArgs e )
        {
            // render frames
            BlackrainEngine.Render();

            // repaint immidiataly
            renderForm.Invalidate();
        }

        private void Run()
        {
            MessagePump.Run( renderForm, BlackrainEngine.Render );
        }

        public string Title
        {
            get { return windowTitle; }
            set { windowTitle = value; }
        }

        public Vector2 Size
        {
            get { return windowSize; }
            set { windowSize = value; }
        }

        public Vector2 Position
        {
            get { return windowPosition; }
            set { windowPosition = value; }
        }

        public bool Resizable
        {
            get { return windowResizable; }
            set { windowResizable = value; }
        }

        public bool MouseEnabled
        {
            get { return windowMouseEnabled; }
            set { windowMouseEnabled = value; }
        }

        public bool Fullscreen
        {
            get { return windowFullscreen; }
            set { windowFullscreen = value; }
        }
    }
}
